import { Component, OnInit, ViewChild, ViewContainerRef, ComponentRef, ComponentFactoryResolver } from '@angular/core';
import { FundPageComponent } from "../content/fund-page/fund-page.component";
import { FundService } from "./fund.service";

@Component({
  selector: 'app-fund',
  templateUrl: './fund.component.html',
  styleUrls: ['./fund.component.scss'],
  providers: [FundService]
})
export class ProductFundComponent implements OnInit {
  // 资金流水页面
  @ViewChild("fundPage", { read: ViewContainerRef })
  fundPage: ViewContainerRef;
  fundPageComponent: ComponentRef<FundPageComponent>;

  constructor(
    public fundService: FundService,
    public resolver: ComponentFactoryResolver
  ) { }

  ngOnInit() {
    this.showFundPage();
  }
  // 资金流水页面
  showFundPage() {
    if (this.fundPageComponent && this.fundPageComponent.instance) {
      this.fundPageComponent.destroy();
    }
    const fundPageComponent = this.resolver.resolveComponentFactory(FundPageComponent);
    this.fundPageComponent = this.fundPage.createComponent(fundPageComponent);
  }
}
